var hotContent = new Array;
var isIn = new Array;
//function areaHot(map){
//	var deployScope = new Array(3);
//    for(var i = 0; i < deployScope.length; i++){
//    	deployScope[i] = {
//    			name : 'luo'+i,
//    			sex : 'male'
//    	}
//    	console.log(deployScope[i]);
//    }	
//
//}
var citymap = {};
function areaHot(map){
	for (var index in dri_id){
		hotContent[index] = '<div id="content">'+
	    '<div id="siteNotice">'+
	    '</div>'+
	    '<h1 id="firstHeading" class="firstHeading">HotareaInfo</h1>'+
	    '<div id="bodyContent">'+
	    '<p><b>WaitingNum: </b>' + '30' +',</b></p>'+
	    '<p><b>DriverNum: </b>' + '2' +',</b></p>'+
	    '<p><b>WaitingIndex: </b>' + '15' +',</b></p>'+ 
	    '<button type="button" id = "autoDeploy">AUTO_DEPLOY</button>'
	    '</div>'+
	    '</div>';
	}

	var center1 = new google.maps.LatLng(39.96215, 116.49127);
	citymap['chicago'] = {
		center : center1,
		population : 28425
	};
	var cityCircle;
	for ( var city in citymap) {
		var populationOptions = {
			strokeColor : '#FF0000',
			strokeOpacity : 0.8,
			strokeWeight : 0.2,
			fillColor : '#FF0000',
			fillOpacity : 0.2,
			map : map,
			center : citymap[city].center,
			radius : citymap[city].population / 20,
			clickable : true
		};
		setTimeout(function(){
			cityCircle = new google.maps.Circle(populationOptions);
			//ADD INFOWINDOW!
			var hot_infowidow;
	        hot_infowidow = new google.maps.InfoWindow({
			content : hotContent[0],
			position : center1
		});
		    google.maps.event.addListener(cityCircle, 'click', function(){
		        hot_infowidow.open(map)
		});
		    addDom(hot_infowidow,city, map);
		},36300)
	    //GET LatLng
//	    google.maps.event.addListener(map, 'click', function(e){
//	        alert(e.latLng);
//	    });
	    
	}
}
		
	
function addDom(hot_infowidow,city, map){
		    var deployScope = new Array(3);
		    for(var i = 0; i < deployScope.length; i++){
		    	var plus = 1.5 + i*0.5;
		        deployScope[i] = {
						strokeColor : 'blue',
						strokeOpacity : 0,
						strokeWeight : 0.4,
						fillColor : 'blue',
						fillOpacity : 0.3,
						map : map,
						center : citymap[city].center,
						radius : citymap[city].population / 20 * plus,
						clickable : true
					};
		    }
		    var deployScope2 = new Array(3);
		    for(var i = 0; i < deployScope2.length; i++){
		    	var plus = 1.5 + i*0.5;
		    	deployScope2[i] = {
						strokeColor : 'black',
						strokeOpacity : 0,
						strokeWeight : 0.1,
						fillColor : 'black',
						fillOpacity : 0.3,
						map : map,
						center : citymap[city].center,
						radius : citymap[city].population / 20 * plus,
						clickable : true
					};
		    };
		    
		    //ADD DOM !
		    google.maps.event.addListener(hot_infowidow, 'domready', function(){
		    	var i = 0;
		        var head = document.getElementById('firstHeading');
		        var autoDeploy = document.getElementById('autoDeploy');
		        google.maps.event.addDomListener(head,"click",function(){
		        	hot_infowidow.close();
		        	});
		        
		        //auto deploy listen (button)!
		        var intv;
		        google.maps.event.addDomListener(autoDeploy,"mouseover",function(){
		        	    intv = setInterval(function(){
		        		i = i % 3;
		        		console.log(i);
		        		var deployCircle = new google.maps.Circle(deployScope[i]);
		        		setTimeout(function(){
		        			deployCircle.setMap(null);
		        		},950)
		        		i++;
		        	},1000)
		        	
	        	});
		        google.maps.event.addDomListener(autoDeploy,"mouseout",function(){
		        	clearInterval(intv);
	        	});
		        google.maps.event.addDomListener(autoDeploy,"click",function(){
		        	var selectI = i - 1;
		        	var distance = (1.5 + i*0.5)*5;
		        	var c = confirm('Driver in : ' + distance +'KM will be notified');
		        	var deployCircle;
		        	if(c == true){
		        		deployCircle = new google.maps.Circle(deployScope[selectI]);
		        		var deployBouds = deployCircle.getBounds();

		        		for(var index in currLat){
		        			
		        			var tempLatLng = new google.maps.LatLng(currLat[index], currLng[index]);
		        			
		        			isIn[index] = deployBouds.contains(tempLatLng);
		        			//console.log(isIn);
//		        			if(isIn[index]){
//		        				changeLineSymble(index);
//		        			}
		        		}
		        		alert('Drivers have received notification!')
		        		setTimeout(function(){
		        			deployCircle.setMap(null);
		        		},1000)
		        	}else{
		        		alert('YOU HAVE CANCELED!');
		        		deployCircle.setMap(null);
		        	}
		        	
		        });
		     
		});
}	    

